<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: '李思',
            age: 18
        }
        let obj1 = {
            sex: '男',
            year: '2002'
        }
        console.log(Object.keys(obj)); // 获取对象的key ["name", "age"]
        console.log(Object.values(obj));// 获取对象的值  ["李思", 18]
        console.log(Object.assign(obj, obj1));//合并对象 {name: "李思", age: 18, sex: "男", year: "2002"}
        console.log(JSON.stringify(Object.entries(obj), null, 2));
        for (const [key, value] of Object.entries(obj)) {
            console.log(key+'=>'+value)
        }

        // 对象复制 浅拷贝 如果对象中有引用类型 修改属性会出现问题 导致原来的对象也会被修改
        let = newObj = {};
        for(const key in obj){
            newObj[key] = obj[key];
        }
        newObj.name = '张三';
        console.log(obj);
        console.log(newObj);

        let obj2 = {...obj};
        obj2.name = 'hehe';
        console.log(obj);
        console.log(obj2);
    </script>
</body>

</html>